/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2008-2012 www.pretty-tools.com
 */

function changeImage(img, src)
{
    img.src = "chrome://webslideshow/skin/" + src;
}

function setDefaultImage(img)
{
    changeImage(img, img.getAttribute("default_image"));
}

function setDefaultImageFor(imageId)
{
    var img = document.getElementById(imageId);
    if (img) setDefaultImage(img);
}

function swapImages(hideImageId,showImageId)
{
    var hideImage = document.getElementById(hideImageId);
    if (hideImage) hideImage.style.display = "none";
    var showImage = document.getElementById(showImageId);
    if (showImage)
    {
        setDefaultImage(showImage);
        showImage.style.display = "block";
    }
}

function createImage(idx)
{
    var image = document.createElement("image");
    // set file index
    image.setAttribute("id", "image" + idx);
    image.setAttribute("idx", idx);
    image.setAttribute("left", "0");
    image.setAttribute("top", "0");

    image.setAttribute("style", "visibility:hidden;");

    return image;
}

function setPosition(elem, left, top)
{
    if (elem)
    {
        elem.setAttribute("left", left);
        elem.setAttribute("top", top);
    }
}

function setPositionLeft(elem, left)
{
    if (elem) elem.setAttribute("left", left);
}

function setPositionTop(elem, top)
{
    if (elem) elem.setAttribute("top", top);
}

function setImageSize(img, size)
{
    img.style.width = size.width + "px";
    img.style.height = size.height + "px";
    img.width = size.width;
    img.minwidth = size.width;
    img.maxwidth = size.width;
    img.height = size.height;
    img.minheight = size.height;
    img.maxheight = size.height;
}

function setTooltip(elem, tooltip)
{
    if (elem) elem.setAttribute("tooltiptext", tooltip);
}

function onLoad(event)
{
    var panel = document.getElementById("slideshow_panel_screen");
    setPosition(panel, (screen.width-panel.width)/2, (screen.height-panel.height));

    gSlideShow.onLoad(event);

    gSlideShow.globalDialogKeeper = yrprxFactory.getGlobalDialogKeeper();
    if (wsshConfig.singleSlideShowDialog && gSlideShow.globalDialogKeeper)
        gSlideShow.globalDialogKeeper.theLastSlideShowDialog = gSlideShow;
    else // do not reset field that were not set by this slideshow
        gSlideShow.globalDialogKeeper = null;
}

function onUnLoad(event)
{
    try
    {
        if (gSlideShow.globalDialogKeeper) // reset dialog reference
            gSlideShow.globalDialogKeeper.theLastSlideShowDialog = null;
    }
    catch(ex)
    {
        if (gSlideShow.logger.enabled) this.logger.error("onUnLoad: ", ex);
    }

    gSlideShow.onUnLoad(event);
}

function onKeyPress(event)
{
    if (event.keyCode == yrprxKeyboardHelper.VK_F11)
        return true;

    gSlideShow.onKeyPress(event);
    return false;
}

function closeWindow()
{
    yrprxBrowser.closeWindow();
}

function showControlPanel()
{
    try
    {
        var panel = document.getElementById("slideshow_panel");

        if (panel && panel.style.display == "none")
            panel.style.display = "";
    }
    catch(ex)
    {
        if (gSlideShow.logger.enabled) gSlideShow.logger.error("showControlPanel: ", ex);
    }
}

function hideControlPanel()
{
    try
    {
        var panel = document.getElementById("slideshow_panel");
        if (panel) panel.style.display = "none";
    }
    catch(ex)
    {
        if (gSlideShow.logger.enabled) gSlideShow.logger.error("hideControlPanel: ", ex);
    }
}

function onSaveImages(event)
{
    try
    {
        if (event && event.which && event.which == 3)
            gSlideShow.saveImage();
        else
            gSlideShow.saveAllImages();
    }
    catch(ex)
    {
        if (gSlideShow.logger.enabled) gSlideShow.logger.error("onSaveImages: ", ex);
    }
}
